//
//  AppDelegate.m
//  Gastrosoph
//
//  Created by 张明磊 on 12-10-14.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "AppDelegate.h"
#import "SKSetFavoriteViewController.h"
#import "SKMainViewController.h"

@implementation AppDelegate

@synthesize window = _window;

@synthesize revealSideViewController = _revealSideViewController;

- (void)dealloc
{
    [_revealSideViewController release];
    
    [_window release];
    
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    [application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
    
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    
    // Override point for customization after application launch.
    
    self.window.backgroundColor = [UIColor clearColor];
    
    //SKSetFavoriteViewController *setFavoriteViewController = [[[SKSetFavoriteViewController alloc] init] autorelease];
    
    //[self.window setRootViewController:setFavoriteViewController];
    
    SKMainViewController *mainViewController = [[[SKMainViewController alloc] init] autorelease];
    
    _revealSideViewController = [[[SKRevealSideViewController alloc]initWithRootViewController:mainViewController] autorelease];
    
    _revealSideViewController.delegate = self;
    
    imageView_startMiddle = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageView_foodDetail_logo.png"]];
    
    [imageView_startMiddle setFrame:CGRectMake(135, 195, 50, 45)];
    
    [self.window addSubview:imageView_startMiddle];
    
    [imageView_startMiddle release];
    
    imageView_startLeft = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageView_startLeft.png"]];
    
    [imageView_startLeft setFrame:CGRectMake(0, 0, 160, 480)];
    
    imageView_startRight = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageView_startRight.png"]];
    
    [imageView_startRight setFrame:CGRectMake(160, 0, 160, 480)];
    
    [self.window addSubview:imageView_startLeft];
    
    [imageView_startLeft release];
    
    [self.window addSubview:imageView_startRight];
    
    [imageView_startRight release];
    
    [UIView beginAnimations:nil context:nil];
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
    [UIView setAnimationDuration:1.0f];
    
    [UIView setAnimationRepeatCount:1];
    
    [UIView setAnimationBeginsFromCurrentState:YES];
    
    [UIView setAnimationDelegate:self];
    
    imageView_startLeft.center = CGPointMake(-80, 240);
    
    imageView_startRight.center = CGPointMake(400, 240);
    
    [UIView commitAnimations];
    
    [self performSelector:@selector(animation_finishedWithApplication:) withObject:application afterDelay:0.01f];
    
    [self.window makeKeyAndVisible];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)animation_finishedWithApplication:(UIApplication *)_application
{
    [imageView_startLeft removeFromSuperview];
    
    [imageView_startRight removeFromSuperview];
    
    [imageView_startMiddle removeFromSuperview];

    [_application setStatusBarHidden:NO];
    
    [self.window setFrame:[[UIScreen mainScreen] bounds]];
    
    self.window.rootViewController = _revealSideViewController;
}

#pragma mark - 
#pragma mark SKRevealSideViewController delegate


@end
